package com.tl.branchmanagementdemo.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.tl.branchmanagementdemo.dao.BranchDao;
import com.tl.branchmanagementdemo.listener.event.UserRegistrationEvent;
import com.tl.branchmanagementdemo.pojo.domain.Branch;
import com.tl.branchmanagementdemo.service.IBranchService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 * 分支表 服务实现类
 * </p>
 *
 * @author tl
 * @since 2024-03-02
 */
@Service
@Slf4j
public class BranchServiceImpl extends ServiceImpl<BranchDao, Branch> implements IBranchService {
    @Autowired
    private ApplicationEventPublisher publisher;
    @Autowired
    private BranchDao branchDao;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void test() throws InterruptedException {
        Branch branch = buildBranch();
        branchDao.insert(branch);
        publisher.publishEvent(new UserRegistrationEvent("11", "xiaomizhou"));

        Thread.sleep(6000);
        log.info("test方法结束");
    }

    @Override
    public void test1() {
//        List<Branch> branches = branchDao.selectList(Wrappers.<Branch>lambdaQuery().eq(Branch::getId, 1L).eq(Branch::getStatus, 1));
        Branch branch = new Branch();
        branch.setId(2L);
        branch.setStatus(4);
        List<Branch> branches = branchDao.customSelect(branch);
        System.out.println(branches);

    }


    private Branch buildBranch() {
        Branch branch = new Branch();
        branch.setParentBranchId(1L);
        branch.setStatus(1);
        branch.setLastVersionId(1L);
        branch.setPath("6777");
        return branch;
    }
}
